package cn.wolfcode.business.controller;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.wolfcode.business.vo.FlowAuditVO;
import cn.wolfcode.business.vo.HistoryVO;
import org.apache.commons.io.IOUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.wolfcode.common.annotation.Log;
import cn.wolfcode.common.core.controller.BaseController;
import cn.wolfcode.common.core.domain.AjaxResult;
import cn.wolfcode.common.enums.BusinessType;
import cn.wolfcode.business.domain.CarPackageAudit;
import cn.wolfcode.business.service.ICarPackageAuditService;
import cn.wolfcode.common.utils.poi.ExcelUtil;
import cn.wolfcode.common.core.page.TableDataInfo;

/**
 * 套餐审核Controller
 * 
 * @author dafei
 * @date 2024-03-07
 */
@RestController
@RequestMapping("/business/carPackageAudit")
public class CarPackageAuditController extends BaseController
{
    @Autowired
    private ICarPackageAuditService carPackageAuditService;

    /**
     * 查询套餐审核列表
     */
    @PreAuthorize("@ss.hasPermi('business:carPackageAudit:list')")
    @GetMapping("/list")
    public TableDataInfo list(CarPackageAudit carPackageAudit)
    {
        startPage();
        List<CarPackageAudit> list = carPackageAuditService.selectCarPackageAuditList(carPackageAudit);
        return getDataTable(list);
    }

    /**
     * 查询套餐审核列表-待办
     */
    @PreAuthorize("@ss.hasPermi('business:carPackageAudit:todo')")
    @GetMapping("/listTodo")
    public TableDataInfo listTodo(CarPackageAudit carPackageAudit)
    {
        //startPage();
        List<CarPackageAudit> list = carPackageAuditService.selectListForTodo(carPackageAudit);
        return getDataTable(list);
    }

    /**
     * 查询套餐审核列表-已办
     */
    @PreAuthorize("@ss.hasPermi('business:carPackageAudit:done')")
    @GetMapping("/listDone")
    public TableDataInfo listDone(CarPackageAudit carPackageAudit)
    {
        //startPage();
        List<CarPackageAudit> list = carPackageAuditService.selectListForDone(carPackageAudit);
        return getDataTable(list);
    }


    /**
     * 导出套餐审核列表
     */
    @PreAuthorize("@ss.hasPermi('business:carPackageAudit:export')")
    @Log(title = "套餐审核", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarPackageAudit carPackageAudit)
    {
        List<CarPackageAudit> list = carPackageAuditService.selectCarPackageAuditList(carPackageAudit);
        ExcelUtil<CarPackageAudit> util = new ExcelUtil<CarPackageAudit>(CarPackageAudit.class);
        util.exportExcel(response, list, "套餐审核数据");
    }

    /**
     * 获取套餐审核详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:carPackageAudit:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(carPackageAuditService.selectCarPackageAuditById(id));
    }

    /**
     * 新增套餐审核
     */
    @PreAuthorize("@ss.hasPermi('business:carPackageAudit:add')")
    @Log(title = "套餐审核", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarPackageAudit carPackageAudit)
    {
        return toAjax(carPackageAuditService.insertCarPackageAudit(carPackageAudit));
    }

    /**
     * 修改套餐审核
     */
    @PreAuthorize("@ss.hasPermi('business:carPackageAudit:edit')")
    @Log(title = "套餐审核", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarPackageAudit carPackageAudit)
    {
        return toAjax(carPackageAuditService.updateCarPackageAudit(carPackageAudit));
    }

    /**
     * 删除套餐审核
     */
    @PreAuthorize("@ss.hasPermi('business:carPackageAudit:remove')")
    @Log(title = "套餐审核", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(carPackageAuditService.deleteCarPackageAuditByIds(ids));
    }

    /**
     * 审核进度
     */
    @PreAuthorize("@ss.hasPermi('business:carPackageAudit:process')")
    @GetMapping("/process/{id}")
    public void process(@PathVariable Long id, HttpServletResponse response) throws IOException {
        InputStream inputStream = carPackageAuditService.getProcessResource(id);
        IOUtils.copy(inputStream, response.getOutputStream());
    }

    /**
     * 撤销套餐审核
     */
    @PreAuthorize("@ss.hasPermi('business:carPackageAudit:cancel')")
    @Log(title = "套餐审核", businessType = BusinessType.UPDATE)
    @PostMapping("/cancel/{id}")
    public AjaxResult cancel(@PathVariable Long id)
    {

        carPackageAuditService.cancelAudit(id);
        return AjaxResult.success();
    }

    /**
     * 套餐审核-历史
     */
    @PreAuthorize("@ss.hasPermi('business:carPackageAudit:history')")
    @GetMapping("/history/{id}")
    public AjaxResult history(@PathVariable Long id)
    {
        //返回值list的泛型 2种操作方案
        //方案1：使用activiti7 原生api：HistoricTaskInstance--优点：直接查询，直接返回，简单  缺点：无法实现定制
        //方案2：使用自定义的vo对象--优点：可以根据页面要求实现定制， 缺点：麻烦需要手动封装数据
        List<HistoryVO> list = carPackageAuditService.auditHistory(id);
        return AjaxResult.success(list);
    }



    /**
     * 撤销套餐审核
     */
    @PreAuthorize("@ss.hasPermi('business:carPackageAudit:audit')")
    @Log(title = "套餐审核", businessType = BusinessType.UPDATE)
    @PostMapping("/audit")
    public AjaxResult audit(@RequestBody FlowAuditVO vo)
    {

        carPackageAuditService.audit(vo);
        return AjaxResult.success();
    }


}
